import { Component, Vue } from "vue-property-decorator";
import { downLoadBase64File } from "@/utils";
@Component
export default class DownLoadTemplateUpLoadMixins extends Vue {
    // 当前操作表单id
    currentFormId: any = ""

    // 下载模板
    async downTemplate(row?: any) {
        const res = await this.$server["task/download/templateForm"]({
            data: {
                formId: row.formId
            }
        });
        if (res.data && res.data.code === 200) {
            downLoadBase64File(row.formName + "-" + "填报模板.xlsx", res.data.data);
        } else {
            this.$message.error(res.data.message || "接口请求错误!");
        }
    }

    getTable() {
        console.log("");
    }

    // 自定义上传文件
    async httpRequest(fileList: any[]) {
        const form = new FormData();
        form.append('formId', this.currentFormId);
        for (let i = 0; i < fileList.length; i++) {
            form.append('file', fileList[i], fileList[i].name);
        }
        const res = await this.$server["moduleManage/fillForm/import"]({
            data: form
        });
        if (res.data.code === 200) {
            const msg = await this.$store.dispatch("importNotice", {
                formId: this.currentFormId
            });
            if (msg) {
                this.$message.success("导入成功，有其他特殊控件无法导入，请前往手动填写");
                this.getTable();
            } else {
                this.$message.success("导入成功");
                this.getTable();
            }
        } else {
            this.$message.error(res.data.message || "接口请求错误!");
        }
    }
}
